import * as API from '../../api'
import * as types from '../mutation-types'
const state = {
    state: {
        userList: {
            page: 1,
            list: [],
            total: 0
        },
        userData: {}
    },
    mutations: {
        [types.GET_PLATE_USER_LIST_SUCCESS] (state, payload) {
            state.userList = payload
        },
        [types.GET_PLATE_USER_DATA_SUCCESS] (state, payload) {
            state.userData = payload
        }
    },
    actions: {
        getPlateList ({commit,state,rootState}, {page, search}) {
            var prom = API.getPlateList({page, search})
            prom.then(function (data) {
                commit(types.GET_PLATE_USER_LIST_SUCCESS, data.result)
                rootState.reqError = null
            })
            .catch(function (err) {
            rootState.reqError = err
            })
            .finally(function () {
            rootState.reqShake++
            })
            return prom
        },
        getPlateDetail ({commit,state,rootState}, userid) {
            var prom = API.getPlateDetail(userid)
            prom.then(function (data) {
                commit(types.GET_PLATE_USER_DATA_SUCCESS, data.result)
                rootState.reqError = null
            })
            .catch(function (err) {
            rootState.reqError = err
            })
            .finally(function () {
            rootState.reqShake++
            })
            return prom
        },
        addSubManager ({commit,state,rootState}, params) {
            var prom = API.addSubManager(params)
            prom.then(function (data) {
                rootState.reqError = null
            })
            .catch(function (err) {
            rootState.reqError = err
            })
            .finally(function () {
            rootState.reqShake++
            })
            return prom
        },
        changeSubMangerInfo ({commit,state,rootState}, {userid, states, auth, duty, comment}) {
            var prom = API.changeSubMangerInfo({userid, states, auth, duty, comment})
            prom.then(function (data) {
                rootState.reqError = null
            })
            return prom
        },
        updateSubManagerState ({commit,state,rootState}, {userid, states, subid}) {
            var prom = API.updateSubManagerState({userid, states, subid})
            prom.then(function (data) {
                rootState.reqError = null
            })
            return prom
        }
    },
    getters: {

    }
}
export default state
